package com.jh.paymentchannel.business.impl;

import java.util.List;

import javax.persistence.EntityManager;

import com.jh.paymentchannel.pojo.HLRegister;
import com.jh.paymentchannel.pojo.RegisterAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jh.paymentchannel.business.RegisterAuthBusiness;
import com.jh.paymentchannel.repository.HLRegisterRepository;
import com.jh.paymentchannel.repository.RegisterAuthRepository;

@Service
public class RegisterAuthBusinessImpl implements RegisterAuthBusiness {

	
	@Autowired
	private RegisterAuthRepository registerAuthRepository;
	@Autowired
	private HLRegisterRepository hlRegisterRepository;
	
	@Autowired
	private EntityManager em;
	
	//增加数据
	@Transactional
	@Override
	public RegisterAuth saveAuth(RegisterAuth registerAuth) {
		
		RegisterAuth result = registerAuthRepository.save(registerAuth);
		em.flush();
		return result;
	}

	//查询数据
	@Override
	public RegisterAuth queryByMobile(String mobile) {
		RegisterAuth queryByRequestId = registerAuthRepository.queryByMobile(mobile);
		return queryByRequestId;
	}

	//修改数据
	@Transactional
	@Override
	public RegisterAuth updateAuth(RegisterAuth registerAuth) {
		RegisterAuth result = registerAuthRepository.save(registerAuth);
		em.flush();
		return result;
	}

//	@Override
//	public HLRegister findHLRegisterByUserId(String userId) {
//		return hlRegisterRepository.findByUserId(userId);
//	}

	@Override
	public Object save(HLRegister model) {
		HLRegister hlr = hlRegisterRepository.save(model);
		em.clear();
		return hlr;
	}
	
	/**
	 * 根据BankCard查询
	 */
	@Override
	public HLRegister findHLRegisterByBankCard(String bankCard) {
		return hlRegisterRepository.findHLRegisterByBankCard(bankCard);
	}

	@Override
	public HLRegister findByBindId(String bindId) {
		return hlRegisterRepository.findByBindId(bindId);
	}

	@Override
	public HLRegister findHLRegisterByBindIdAndBankCard(String bindId, String bankCard) {
		return hlRegisterRepository.findByBindIdAndBankCard(bindId,bankCard);
	}

	@Override
	public List<HLRegister> findByUserId(String userId) {
		return hlRegisterRepository.findByUserIdList(userId);
	}
	

}
